/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.core.service.ruler.impl;

import com.playground.core.entity.boardgame.BoardGame;
import com.playground.core.entity.boardgame.Move;
import com.playground.core.entity.boardgame.Piece;
import com.playground.core.service.ruler.ChessLikeGameRuler;

/**
 *
 * @author Tiago Peres
 */
public abstract class ChessLikeGameRulerImpl extends BoardGameRulerImpl implements ChessLikeGameRuler {
    public boolean executeMove(BoardGame game, Move move){
        if (isMoveAllowed(game, move)){
            Piece p = move.getSource().getPiece();
            game.getBoard().movePiece(p, move.getDestination());
            executeReactions(game, move);
            game.setNumberOfMoves(game.getNumberOfMoves() + 1);
            endTurn(game, move);
            return true;
        }
        return false;
    }
    
    /**
     * Execute the reactions in the board after executing the given move. In a 
     * checkers game, for instance, it can transform a simple piece into a king 
     * and eliminate enemy pieces from the board.
     * 
     * @param game the game to apply te rules
     * @param move the move to have it's consequences
     * @return the destination square
     */
    protected abstract void executeReactions(BoardGame game, Move move);
}
